layui.define(['table', 'form'], function(exports){
  var $ = layui.$,table = layui.table,form = layui.form;

  var deviceSn = $('input[name="deviceSn"]').val();

  table.render({
    elem: '#LAY-table'
    ,url: layui.setter.webRoot + '/bxscn/device/portable_battery/order/list.data'
      ,where:{portableBatterySn:deviceSn}
    ,method: 'post'
    ,parseData: function (res) {
        return {
            "code": res.code,
            "msg": res.msg,
            "count": res.body.total,
            "data": res.body.data
        };
    }
    ,response: {statusCode: 200}
    ,cols: [[
       {field: 'tradeNo', title: '订单号'}
      ,{field: 'leaseChargingCabinetSn', title: '租借机柜',templet:function (record){
          if(record.leaseChargingCabinetSn) {
              return record.leaseChargingCabinetSn + '(卡槽：' + record.leaseSlotNum + ')';
          }else{
              return '--';
          }
      }}
      ,{field: 'leaseAreaName', title: '租借地区'}
      ,{field: 'leasePower', title: '租借电量'}
      ,{field: 'revertChargingCabinetSn', title: '归还机柜',templet:function (record){
          if(record.revertChargingCabinetSn) {
              return record.revertChargingCabinetSn + '(卡槽：' + record.revertSlotNum + ')';
          }else{
              return '--';
          }
      }}
      ,{field: 'revertAreaName', title: '归还地区'}
      ,{field: 'revertPower', title: '归还电量'}
      ,{field: 'useDurationStr', title: '使用时长'}
      ,{field: 'stateName', title: '订单状态'}
      ,{field: 'createDate', title: '创建时间'}
      ,{title: '操作', width: 80, align:'center', fixed: 'right', toolbar: '#LAY-table-toolbar'}
    ]]
    ,page: false
    ,text: '对不起，加载出现异常！'
  });
  
  //事件
  var active = {
      info: function(obj){
          layer.open({
              type: 2
              ,title: '查看订单'
              ,content: layui.setter.webRoot + '/bxscn/order/info.html?tradeNo='+obj.data.tradeNo
              ,maxmin: true
              ,area: ['80%', '80%']
          });
      }
  };
  
  $('.layui-btn.LAY-btn-fun').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
  
  table.on('tool(LAY-table)', function(obj){
  	var type = obj.event ;
   	active[type] ? active[type].call(this,obj) : '';
  });
  
  exports('portable_energy_battery_info', {})
});